{{define "user/edit.html"}}
<!DOCTYPE html>
<html>
	<head>
        {{template "header"}}
	</head>

	<body>
		<div class="weadmin-nav">
            <span class="layui-breadcrumb">
                <a href="/welcome">首页</a>
                <a href="/admin/user/list">用户管理</a>
                <a><cite>修改用户</cite></a>
            </span>
		</div>
		<div class="weadmin-body">
			<form class="layui-form" lay-filter="user_edit">
				<div class="layui-form-item">
					<div class="layui-inline">
						<label for="L_username" class="layui-form-label">
							<span class="we-red">*</span>用户名
						</label>
						<div class="layui-input-inline layui-text">
							{{.user.Username}}
							<input type="hidden" name="user" lay-filter="user" value="">
							<input type="password" name="pwd" lay-filter="pwd" id="pwd" value="" style="display:none">
						</div>
					</div>

					<div class="layui-inline">
						<label for="L_orgid" class="layui-form-label">
							所属机构
						</label>
						<div class="layui-input-inline">
							<select name="orgid" lay-filter="orgid" id="L_orgid">
								<option value="0">请选择</option>
								{{ range .parentOrgList }}
								<option value="{{.Value}}">{{.Text}}</option>
								{{ end }}
							</select>
						</div>
					</div>
				</div>

				<div class="layui-form-item">
					<div class="layui-inline">
						<label for="L_email" class="layui-form-label">
							<span class="we-red">*</span>手机
						</label>
						<div class="layui-input-inline">
							<input type="text" id="L_phone" name="phone" lay-verify="phone" autocomplete="" class="layui-input" value="">
						</div>
					</div>

					<div class="layui-inline">
						<label for="L_gender" class="layui-form-label">性别</label>
						<div class="layui-input-block" id="L_gender">
							<input type="radio" name="gender" lay-verify="gender" value="男" title="男">
							<input type="radio" name="gender" lay-verify="gender" value="女" title="女">
						</div>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-inline">
						<label for="L_email" class="layui-form-label">
							邮箱
						</label>
						<div class="layui-input-inline">
							<input type="text" id="L_email" name="email" lay-verify="email" autocomplete="off" class="layui-input" value="">
						</div>
					</div>

					<div class="layui-inline">
						<label for="L_state" class="layui-form-label">状态</label>
						<div class="layui-input-block" id="L_state">
							<input type="checkbox" name="state" id="L_state" lay-verify="state" lay-skin="switch"
								lay-text="启用|禁用" value="1">
						</div>
					</div>
				</div>

				<div class="layui-form-item">
					<button class="layui-btn fr" lay-filter="edit" lay-submit="">确定</button>
				</div>
			</form>
		</div>
    </body>

    {{template "jsfile"}}
	<script type="text/javascript">
		layui.extend({
			admin: '/static/js/admin',
		});
		layui.use(['jquery', 'form','element', 'admin', 'carousel'], function() {
			var element = layui.element,
				$ = layui.jquery,
				carousel = layui.carousel,
				form = layui.form,
				admin = layui.admin;

			//监听提交
			form.on('submit(edit)', function(data){
				$.ajax({
					url:'/admin/user/edit/'+'{{.user.Id}}',
					type:'PUT',
					data:data.field,
					dataType:'json',
					success: function(result){
						if(result.status){
							layer.msg("更新用户信息成功!",{time:3*1000,icon:1},function(){
								//自动关闭layer
								var index = parent.layer.getFrameIndex(window.name);
								parent.layer.close(index);
								//刷新list
								parent.userRefreshForm();
							})
						}else{
							layer.msg(result.message,{time:6*1000,icon:2})
						}
					}
				})
				return false;
			});

			form.val('user_edit', {
				"user": '{{.user.Username}}',
				"pwd": '{{.user.Username}}',
				"orgid": '{{.user.Orgid}}',
				"state": {{.user.State}},
				"phone": '{{.user.Phone}}',
				"email": '{{.user.Email}}',
				"gender": '{{.user.Gender}}'
			});
		});
	</script>

</html>
{{end}}